package com.yt.order.common.utils;

//运算符
public class OperatorUtils {
    //left验证的值（星级、距离、单量）
    //operator运算符(>,<,==,=>,=<)
    //right阈值（比较的值）
    public static boolean compare(Number left, String operator, Number right) {
        if (left == null || right == null || operator == null) {
            return false;
        }
        double leftVal = left.doubleValue();
        double rightVal = right.doubleValue();

        switch (operator) {
            case ">":
                return leftVal > rightVal;
            case "<":
                return leftVal < rightVal;
            case ">=":
                return leftVal >= rightVal;
            case "<=":
                return leftVal <= rightVal;
            case "==":
                return leftVal == rightVal;
            default:
                throw new IllegalArgumentException("不支持的运算符：" + operator);
        }
    }
}
